home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_d / aspell22.zip / ACROPS32.PAS < prev    next >
Pascal/Delphi Source File  |  1996-03-27  |  5KB  |  188 lines

  1. unit Acrops32;
  2.  
  3. interface
  4.  
  5. { A silly wrapper component to hide the real code in the BsASpl32 unit }
  6.  
  7. { Revisions:
  8.      1/24/96  - Corrected problem in Create/Free not initializing properly
  9. }
  10.  
  11. uses
  12.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  13.   Forms, Dialogs;
  14.  
  15.  
  16. type
  17.   TAcropSpell = class(TComponent)
  18.   private
  19.     { Private declarations }
  20.     DictDataPtr         : pointer;
  21.     FIsDictionaryOpen   : boolean;
  22.     FDictionaryMain     : string;
  23.     FDictionaryUser     : string;
  24.     FMaxSuggestions     : byte;
  25.   protected
  26.     { Protected declarations }
  27.   public
  28.     { Public declarations }
  29.     constructor Create(AOwner : TComponent); override;
  30.     procedure Free;
  31.     function OpenDictionary(Filename : STRING) : boolean;
  32.     function OpenUserDictionary(Filename : STRING) : integer;
  33.     procedure CloseDictionaries;
  34.     function GoodWord(TheWord : STRING) : BOOLEAN;
  35.     function AddWord(TheWord : STRING; DictID : integer) : BOOLEAN;
  36.     function SuggestCloseMatch(TheWord : STRING) : TStringList;
  37.     function SuggestPhoneme(TheWord : STRING) : TStringList;
  38.     function GetUserDictionaryList(DictID : integer) : TStringList;
  39.     function CloseUserDictionary(DictID : INTEGER) : BOOLEAN;
  40.     function DeleteUserDictionary(DictID : integer) : BOOLEAN;
  41.     procedure DeleteUserDictionaries;
  42.     procedure CloseUserDictionaries;
  43.     function BuildUserDictionary(Filename : STRING; WordList : TStringList) : INTEGER;
  44.     function IsDictionaryOpen : boolean;
  45.     procedure SetMaxSuggestions(Max : byte);
  46.   published
  47.     { Published declarations }
  48.     property DictionaryName : string read FDictionaryMain write FDictionaryMain;
  49.     property DictionaryUser : string read FDictionaryUser write FDictionaryUser;
  50.     property MaxSuggestions : byte read FMaxSuggestions write SetMaxSuggestions default 10;
  51.   end;
  52.  
  53. procedure Register;
  54.  
  55. implementation
  56.  
  57. uses BsASpl32;
  58.  
  59. procedure Register;
  60. begin
  61.   RegisterComponents('Samples', [TAcropSpell]);
  62. end;
  63.  
  64.  
  65. constructor TAcropSpell.Create(AOwner : TComponent);
  66. begin
  67.   inherited Create(AOwner);
  68.   FIsDictionaryOpen   := FALSE;
  69.   FDictionaryMain     := 'acrop.dct';
  70.   FDictionaryUser     := 'custom.dct';
  71.   FMaxSuggestions     := 10;
  72.   BsASpl32.InitDictionaryData(DictDataPtr);
  73. end;
  74.  
  75. procedure TAcropSpell.Free;
  76. begin
  77.   if FIsDictionaryOpen then
  78.     CloseDictionaries;
  79.   BsASpl32.ReleaseDictionaryData(DictDataPtr);
  80.   inherited Free;
  81. end;
  82.  
  83. procedure OpenDefaultDictionary(AOwner : TAcropSpell);
  84. begin
  85.   with AOwner do
  86.     begin
  87.       FIsDictionaryOpen := OpenDictionary(FDictionaryMain);
  88.     end;
  89. end;
  90.  
  91. procedure TAcropSpell.SetMaxSuggestions(Max : byte);
  92. begin
  93.   if Max > 30 then
  94.     Max := 30;
  95.   FMaxSuggestions := Max;
  96. end;
  97.  
  98. function TAcropSpell.OpenDictionary(Filename : STRING) : boolean;
  99. begin
  100.   OpenDictionary := FALSE;
  101.   if FIsDictionaryOpen then
  102.     exit;
  103.   if BsASpl32.OpenDictionary(DictDataPtr, Filename) then
  104.     begin
  105.       FIsDictionaryOpen := TRUE;
  106.       FDictionaryMain   := Filename;
  107.       OpenDictionary    := TRUE;
  108.     end;
  109. end;
  110.  
  111. function TAcropSpell.OpenUserDictionary(Filename : STRING) : integer;
  112. begin
  113.   OpenUserDictionary := BsASpl32.OpenUserDictionary(DictDataPtr, Filename);
  114. end;
  115.  
  116. procedure TAcropSpell.CloseDictionaries;
  117. begin
  118.   if not FIsDictionaryOpen then
  119.     exit;
  120.   BsASpl32.CloseDictionaries(DictDataPtr);
  121.   FIsDictionaryOpen := FALSE;
  122. end;
  123.  
  124. function TAcropSpell.GoodWord(TheWord : STRING) : BOOLEAN;
  125. begin
  126.   if not FIsDictionaryOpen then
  127.     OpenDefaultDictionary(Self);
  128.   GoodWord := BsASpl32.GoodWord(DictDataPtr, TheWord);
  129. end;
  130.  
  131. function TAcropSpell.AddWord(TheWord : STRING; DictID : integer) : BOOLEAN;
  132. begin
  133.   if not FIsDictionaryOpen then
  134.     OpenDefaultDictionary(Self);
  135.   AddWord := BsASpl32.AddWord(DictDataPtr, TheWord, DictID);
  136. end;
  137.  
  138. function TAcropSpell.SuggestCloseMatch(TheWord : STRING) : TStringList;
  139. begin
  140.   if not FIsDictionaryOpen then
  141.     OpenDefaultDictionary(Self);
  142.   SuggestCloseMatch := BsASpl32.SuggestCloseMatch(DictDataPtr, TheWord, FMaxSuggestions);
  143. end;
  144.  
  145. function TAcropSpell.SuggestPhoneme(TheWord : STRING) : TStringList;
  146. begin
  147.   if not FIsDictionaryOpen then
  148.     OpenDefaultDictionary(Self);
  149.   SuggestPhoneme := BsASpl32.SuggestPhoneme(DictDataPtr, TheWord, FMaxSuggestions);
  150. end;
  151.  
  152. function TAcropSpell.GetUserDictionaryList(DictID : integer) : TStringList;
  153. begin
  154.   GetUserDictionaryList := BsASpl32.GetUserDictionaryList(DictDataPtr, DictID);
  155. end;
  156.  
  157. function TAcropSpell.CloseUserDictionary(DictID : INTEGER) : BOOLEAN;
  158. begin
  159.   CloseUserDictionary := BsASpl32.CloseUserDictionary(DictDataPtr, DictID);
  160. end;
  161.  
  162. function TAcropSpell.DeleteUserDictionary(DictID : integer) : BOOLEAN;
  163. begin
  164.   DeleteUserDictionary := BsASpl32.DeleteUserDictionary(DictDataPtr, DictID);
  165. end;
  166.  
  167. procedure TAcropSpell.DeleteUserDictionaries;
  168. begin
  169.   BsASpl32.DeleteUserDictionaries(DictDataPtr);
  170. end;
  171.  
  172. procedure TAcropSpell.CloseUserDictionaries;
  173. begin
  174.   BsASpl32.CloseUserDictionaries(DictDataPtr);
  175. end;
  176.  
  177. function TAcropSpell.BuildUserDictionary(Filename : STRING; WordList : TStringList) : integer;
  178. begin
  179.   BuildUserDictionary := BsASpl32.BuildUserDictionary(DictDataPtr, Filename, WordList);
  180. end;
  181.  
  182. function TAcropSpell.IsDictionaryOpen : boolean;
  183. begin
  184.   IsDictionaryOpen := FIsDictionaryOpen;
  185. end;
  186.  
  187. end.
  188.